var app = getApp();

var dateTimePicker = require('../resource/js/dateTimePicker.js');

Page({
    data:{
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        
        var joinid = options.joinid ? options.joinid : '';
        var type = options.type ? options.type : '';
        self.setData({
            options : options,
            type : type
        });
        app.com.auth(function(user){
            app.com.http('webadmin','POST',{op:'verify',joinid:joinid,type : type},0,false,'','',function(res){
                if (!res.data.errno && res.data) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        params : res.data.data.params,
                        user : res.data.data.user,
                        join : res.data.data.join,
                        sort : res.data.data.sort,
                        inited : true,
                    });

                    var obj1 = dateTimePicker.dateTimePicker(2018,2030,0);
                    var obj2 = dateTimePicker.dateTimePicker(2018,2030,0);

                    obj1.dateTimeArray.pop();
                    obj1.dateTime.pop();

                    self.setData({
                        'dateTimeArray.end': obj1.dateTimeArray,
                        'dateTime.end': obj1.dateTime,
                    });

                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '',
        });
       
    },
    pass(){
        var self = this;
        var join = JSON.stringify( self.data.join );
        app.com.http('webadmin','POST',{op:'verifypass',join:join,type:self.data.type},0,true,'','',function(res){
            app.com.alert(res.data.message);
            if (!res.data.errno && res.data) {
                self.setData({
                    subed : true,
                });
            }
        });
    },
    inputvalue(e){
        var self = this;
        var type = e.currentTarget.dataset.type;
        var value = e.detail.value;
        self.setData({
            ['join.'+type] : value,
        })
    },
    getsortvalue(e){
        var self = this;
        var value = e.detail.value;
        for (let i = 0,il = self.data.sort; i < il.length; i++) {
            if( i == value ){
                self.setData({
                    'join.sortid' : il[i].id,
                    'join.sortname' : il[i].name,
                })
            }
        }
    },
    changeDateTimeColumn1(e) {
        var self = this;
        var type = e.currentTarget.dataset.type;
        var value = e.detail.value;
        self.setData({ 
            ['dateTime.'+type]: e.detail.value,
            ['join.'+type] : self.data.dateTimeArray[type][0][value[0]]+'-'+self.data.dateTimeArray[type][1][value[1]]+'-'+self.data.dateTimeArray[type][2][value[2]]+' '+self.data.dateTimeArray[type][3][value[3]]+':'+self.data.dateTimeArray[type][4][value[4]]
        });

    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})